package com.wgts.wgts.mvp.view.activity.guessing;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.control.nestedscrollview.ColorFlipPagerTitleView;
import com.wgts.wgts.mvp.view.activity.myorder.MyOrderActivity;
import com.wgts.wgts.mvp.view.activity.myorder.MyOrderFragmentAdapter;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/*
 *
 *
 *   data:2018/10/516:19
 *
 */public class MyGuessingActivity extends BaseActivity {

    @BindView(R.id.back_btn_image)
    ImageView backBtnImage;
    @BindView(R.id.back_btn_ly)
    LinearLayout backBtnLy;
    @BindView(R.id.include_title)
    TextView includeTitle;
    @BindView(R.id.include_text)
    TextView includeText;
    @BindView(R.id.include_right_image)
    ImageView includeRightImage;
    @BindView(R.id.include_right_ly)
    LinearLayout includeRightLy;
    @BindView(R.id.my_guessing_tab)
    MagicIndicator myGuessingTab;
    @BindView(R.id.my_guessing_view_page)
    ViewPager myGuessingViewPage;
    private List<String> list;
    private GuessingViewPageAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_guessing_activity);
        ButterKnife.bind(this);
        initView();
        includeTitle.setText("我的");
    }

    @Override
    public void init() {

    }

    private void initView() {
        list = new ArrayList<>();
        list.add(0, "我的奖品");
        list.add(1, "订单");
        adapter = new GuessingViewPageAdapter(getSupportFragmentManager(), list);
        myGuessingViewPage.setAdapter(adapter);
        initMagicIndicator();
    }

    @OnClick(R.id.back_btn_ly)
    public void onViewClicked() {
        finish();
    }

    private void initMagicIndicator(){
        adapter = new GuessingViewPageAdapter(getSupportFragmentManager(), list);
        myGuessingViewPage.setAdapter(adapter);

        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setScrollPivotX(0.65f);
        commonNavigator.setAdjustMode(true);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return list == null ? 0 : list.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                SimplePagerTitleView simplePagerTitleView = new ColorFlipPagerTitleView(context);
                simplePagerTitleView.setText(list.get(index));
                simplePagerTitleView.setNormalColor(ContextCompat.getColor(MyGuessingActivity.this, R.color.hint_6));
                simplePagerTitleView.setSelectedColor(ContextCompat.getColor(MyGuessingActivity.this, R.color.home_page_color));
                simplePagerTitleView.setTextSize(14);
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        myGuessingViewPage.setCurrentItem(index, false);
                    }
                });
                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator indicator = new LinePagerIndicator(context);
                indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
                indicator.setLineHeight(UIUtil.dip2px(context, 2));
                indicator.setLineWidth(UIUtil.dip2px(context, 52));
                indicator.setRoundRadius(UIUtil.dip2px(context, 1));
                indicator.setYOffset(UIUtil.dip2px(context, 5));
                indicator.setStartInterpolator(new AccelerateInterpolator());
                indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));
                indicator.setColors(getResources().getColor( R.color.home_page_color));
                return indicator;
            }
        });
        myGuessingTab.setNavigator(commonNavigator);
        ViewPagerHelper.bind(myGuessingTab, myGuessingViewPage);
    }
}
